﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;
using KPIS.Utils;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PR_SalaryGroup : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private IEmployeeTypeBLL empTypeBLL = new EmployeeTypeBLL();
        private SalaryGroupBLL salaryGroupBLL = new SalaryGroupBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindEmpType();
                LoadDataGrid();
            }

        }

        private void LoadDataGrid()
        {
            string EmpTypeSeq = ddlEmployeeType.SelectedValue;
            string Active = ddlStatusActive.SelectedValue;
            bool bGovernment = EmpTypeSeq == "1";
            try
            {
                if (EmpTypeSeq != "")
                {
                    DataSet salaryGroupList = bGovernment ? salaryGroupBLL.ListSalaryGroupGovernment(Active, EmpTypeSeq) : salaryGroupBLL.ListSalaryGroup(Active, EmpTypeSeq);
                    RadGrid2.DataSource = salaryGroupList.Tables[0];
                    RadGrid2.DataBind();
                    RadGrid2.Columns[5].Visible = bGovernment;
                    RadGrid2.Columns[6].Visible = bGovernment;
                    RadGrid2.Columns[7].Visible = bGovernment;
                } 
            }
            catch (Exception ex)
            {
                Web.ShowAlert(this, ex.Message);
            }
        }
        private void bindEmpType()
        {
            try
            {
                IList<EmployeeTypeInfo> infoList = empTypeBLL.ListEmployeeTypes();
                ddlEmployeeType.DataSource = infoList;
                ddlEmployeeType.DataBind();

            }
            catch
            {

            }
        }
        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Delete")
                {
                    int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["sal_grp_seq"]);
                    salaryGroupBLL.Delete(seq, ssMng.EmpSeq);
                }
                if (e.CommandName == "ExpandCollapse")
                    return;
                LoadDataGrid();
            }
            catch (Exception ex)
            {
                Web.ShowAlert(this, ex.Message);
            }
        }
        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            LoadDataGrid();
            //if (e.Argument == "Rebind")
            //{
            //    RadGrid2.MasterTableView.SortExpressions.Clear();
            //    RadGrid2.MasterTableView.GroupByExpressions.Clear();
            //}
            //else if (e.Argument == "RebindAndNavigate")
            //{
            //    RadGrid2.MasterTableView.SortExpressions.Clear();
            //    RadGrid2.MasterTableView.GroupByExpressions.Clear();
            //    RadGrid2.MasterTableView.CurrentPageIndex = RadGrid2.MasterTableView.PageCount - 1;                
            //}
            //RadGrid2.Rebind();
        }

        protected void ddlStatusActive_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadDataGrid();
        }
        protected void ddlEmployeeType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (!string.IsNullOrEmpty(ddlEmployeeType.SelectedValue))
                Session["EMP_TYPE_SEQ"] = ddlEmployeeType.SelectedValue;

            LoadDataGrid();
        }


    }
}
